package com.hzz.web.app.user;


import com.hzz.api.user.IUserService;
import com.hzz.dto.user.UserDto;
import com.hzz.framework.PageUtil;
import com.hzz.framework.Response;
import com.hzz.framework.config.EncryptConfig;
import com.hzz.framework.util.CommonConstant;
import com.hzz.framework.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "组织体系-河长信息")
@RestController("apiRiverSupervisorController")
@Slf4j
public class RiverSupervisorController extends BaseController {
    @Autowired
    EncryptConfig encryptConfig;
    @Autowired
    IUserService userService;
    static final String acPrefix = "/api/staff/riverSupervisor/";


    //@RequiresPermissions("riverSupervisor:menu")
    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = acPrefix + "page/{pageNum}")
    @ApiOperation(value = "信息分页(未删除)")
    public Response page(@RequestBody UserDto dto, @PathVariable("pageNum") Integer pageNum) {
        log.info("page.........");
        Response result = new Response();
        try {
            dto.setPageSize(CommonConstant.PAGEROW_DEFAULT_COUNT);
            dto.setPageNum(pageNum);
            dto.setDelFlag(0);
            dto.setTypes(CommonConstant.TYPES_各河长);
            result.data = PageUtil.copy(userService.findDataIsPage(dto));
        } catch (Exception e) {
            result = Response.error(e.getMessage());
        }
        return result;
    }

    //@RequiresPermissions("riverSupervisor:info")
    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = acPrefix + "info/{id}")
    @ApiOperation(value = "信息详情")
    public Response info(@PathVariable("id") Long id) {
        log.info("info.........");
        Response result = new Response();
        try {
            UserDto dto = new UserDto();
            dto.setId(id);
            dto.setDelFlag(0);
            dto.setTypes(CommonConstant.TYPES_各河长);
            result.data = userService.findDataById(dto);
        } catch (Exception e) {
            result = Response.error(e.getMessage());
        }
        return result;
    }

    /**
     * 所有河长信息，用于其他功能选择
     * @param dto
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = acPrefix + "list")
    @ApiOperation(value = "信息详情")
    public Response<List<UserDto>> list(UserDto dto) {
        log.info("list.........");
        Response<List<UserDto>> result = new Response<>();
        try {
            dto.setTypes(CommonConstant.TYPES_各河长);
            result.data = userService.findDataIsList(dto);
        } catch (Exception e) {
            result = Response.error(e.getMessage());
        }
        return result;
    }
}
